package net.cl.mvc.config;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.FilterConfig;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Configuration {

	private static final Log log = LogFactory.getLog(Configuration.class);
	private static final Map<String, Object> map = new HashMap<String, Object>();
	private static final Map<String, String> FILTER_CONFIG = new HashMap<String, String>();

	public static String getString(String key) {
		return (String) map.get(key);
	}

	public static void initFilterConfig(FilterConfig filterConfig) {
		if (filterConfig == null) {
			log.debug("FilterConfig is null.");
			return;
		}
		Enumeration<?> enu = filterConfig.getInitParameterNames();
		if (enu == null || !enu.hasMoreElements()) {
			log.debug("No init parameter is applied for FilterConfig.");
			return;
		}
		while (enu.hasMoreElements()) {
			String s = (String) enu.nextElement();
			FILTER_CONFIG.put(s, filterConfig.getInitParameter(s));
		}
	}

	public static String getFilterConfigInitParameter(String key) {
		return FILTER_CONFIG.get(key);
	}

}
